
$(function(){
	layui.use(['element','layer'], function() {
		var index = layer.load(1,{
			shade:[0.5,'black'] //第一个参数透明度 ，第二个参数是颜色
		});
		var element = layui.element;
		$(document).on("click", ".li_item", function() {
			var dataId = $(this).data("id");
			if($("#ifm_" + dataId).length > 0) {
				element.tabChange("demo", "lid_" + dataId)
			} else {
				var title = $(this).text();
				var url = $(this).data("url");
				element.tabAdd("demo", {
					title: title,
					content: "<iframe src='" + url + "' id='ifm_" + dataId + "'></iframe>",
					id: "lid_" + dataId
				});
				element.tabChange("demo", "lid_" + dataId);
			}
		});
	
	
	
		function username(){
			var img=localStorage.getItem("headImg");
				$(".username").append("<img src='"+img+"'  class='layui-nav-img'>"+localStorage.getItem("userName"));
				
			
			}
			username();
			
			//查找菜单
			function find_myMenu() {
				$.ajax({
					type:"get",
					url:"../../base/data/caidan.json",
					async:true,
					/*"beforeSend":function(){
						layer.load(1,{
							shade:[0.5,"red"]//  背景阴影，第一个透明度，第二个颜色
						});
					},*/
					
					"success":function(result){
						if(result.resultCode==0){
							build_MyMenu(result);
							layer.close(index);
        					element.init();//这里是给layui从新渲染一遍
						}else{
							layer.msg(result.message,{
								icon:2,
								time:1000
							});
						}
					}
				});	
			}
				
				
			function build_MyMenu(result){
				
				$.each(result.data.menu_1,function(infoindex,info){
					var li=$("<li class='layui-nav-item'></li>");	
					var a=$("<a href='javascript:;' data-id='"+info.code+"' data-url=''><i class='fa fa-cogs' aria-hidden='true'></i>&nbsp;"+info.name+"</a>");
					var dl=$("<dl class='layui-nav-child'></dl>");
					var code=info.code;
					$.each(result.data.menu_2,function(infoindex,info){
						if(info.fk_parent_id==code){
							var asd=$("<dd><a class='li_item' data-id='"+info.code+"' data-url='"+info.url+"'  ><i class='fa fa-address-book' aria-hidden='true'></i>&nbsp;"+info.name+"</a><dd>");
							dl.append(asd);
						}
					});
					li.append(a);
					li.append(dl);
					$(".dierji").append(li);
				});
			}
			find_myMenu();	
});
});

	